#include "NieuwMapDialog.h"

#include <QGridLayout>
#include <QPushButton>
#include <QIntValidator>
#include <QLineEdit>
#include <QLabel>

NieuwMapDialog::NieuwMapDialog(QWidget* parent, Qt::WFlags f)
	: QDialog(parent, f)
{
	setModal(true);
	QGridLayout* layout = new QGridLayout(this);
	this->setLayout( layout );

 	QValidator *validator = new QIntValidator(5, 999, this);
    breedteLE = new QLineEdit(this);
    // the edit lineedit will only accept integers between 100 and 999
   	breedteLE->setValidator(validator);
    hoogteLE = new QLineEdit(this);
    // the edit lineedit will only accept integers between 100 and 999
    hoogteLE->setValidator(validator);
		
	QLabel* breedteLabel = new QLabel("Breedte: ", this);
	layout->addWidget(breedteLabel, 0,0, 1, 1);	
	QLabel* hoogteLabel = new QLabel("Hoogte: ", this);
	layout->addWidget(hoogteLabel, 1, 0, 1, 1);
	layout->addWidget(breedteLE, 0,1, 1, 1);
	layout->addWidget(hoogteLE, 1,1, 1, 1);
	
	
	QPushButton* cancelButton = new QPushButton(tr("&Annuleer"), this);
	QObject::connect( cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
	layout->addWidget(cancelButton, 2, 0, 1, 1);
	QPushButton* okButton = new QPushButton(tr("&Ok"), this);
	QObject::connect( okButton, SIGNAL(clicked()), this, SLOT(accept()));
	layout->addWidget(okButton, 2, 1, 1, 1);
}

void NieuwMapDialog::accept()
{
	if( width() > 4 && height() > 4 )
	{
		QDialog::accept();
	}
 	else 
	{
		if( width() < 4 )
			breedteLE->setText("5");	
		if( height() < 4 )
			hoogteLE->setText("5");	
	}	
}

int NieuwMapDialog::width()
{
	return breedteLE->text().toInt();
}
int NieuwMapDialog::height()
{
	return hoogteLE->text().toInt();
}
